/**
 * 登录输出数据，是否登录成功
 */
interface LoginOutPutListItemResponse extends BaseResponse {
    /**
     * 用户编号
     */
    id:number;
    /**
     * 用户名
     */
    userName:string;
    /**
     * 真实姓名
     */
    realName:string;
    /**
     * 部门名称
     */
    userGroup:string;
    /**
     * 专员类型
     */
    commissionerType:Array<string>;
    /**
     * 融云Token
     */
    rongToken:string;
    /**
     * web 融云token
     */
    webRongToken:string;
    /**
     * 2018-1-16新增：个人信息里的头像
     */
    headPath:string
}


/**
 *登录服务 
 */
interface ILoginService {
    /**
     * 登录
     * @param userName 用户名
     * @param password 密码
     */
    login(userName: string, password:string): ng.IHttpPromise<LoginOutPutListItemResponse>;
    /**
     * 登出
     */
    loginOut(): ng.IHttpPromise<any>;
    /**
     * 是否登录
     */
    isLogin(): ng.IHttpPromise<any>;

    /**
     * 新增版本号
     * @param platform 平台
     * @param version 版本记录   
     * @param versionSummary 版本说明
     */
    addVersionInfo(platform:string,version:string,versionSummary:string): ng.IHttpPromise<BaseResponse>;

    /**
     * 获取版本号
     */
    getVersionInfo(): ng.IHttpPromise<any>

}

class LoginService implements ILoginService {
    constructor(private http: ng.IHttpService, private route: routeService) {
    }

    login(userName: string, password:string): ng.IHttpPromise<LoginOutPutListItemResponse> {
        return this.http<LoginOutPutListItemResponse>({
            method: "PUT",
            url: this.route.getUrl("login"),
            data: {
                userName:userName,
                password:password,
                platform:1
            }

        });
    }

    loginOut(): ng.IHttpPromise<any> {
        return this.http<any>({
            method: "PUT",
            url: this.route.getUrl("login/logout")
        });
    }

    isLogin(): ng.IHttpPromise<any> {
        return this.http<any>({
            method: "GET",
            url: this.route.getUrl("login/IsLogin")
        });
    }

    addVersionInfo(platform:string,version:string,versionSummary:string): ng.IHttpPromise<BaseResponse>{
        return this.http<BaseResponse>({//AddCCPCarAttachment?id={{id}}
            method: "POST",
            url: this.route.getUrl("version/AddVersionInfo"),////?platform={{platform}}&version={{version}}&versionSummary={{versionSummary}}
            data:{
                platform:platform,
                version:version,
                versionSummary:versionSummary
            }
        });
    }

    getVersionInfo(): ng.IHttpPromise<any> {
        return this.http<any>({
            method: "GET",
            url: this.route.getUrl("version/GetVersionInfo")
        });
    }
    

}
angular.module("loginService",[]).service("loginService",['$http','routeService',LoginService]);